In [1]:
import matplotlib.pyplot as plt
In [6]:
fig, ax = plt.subplots()


ax.plot()
plt.show()
In [18]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4] )

#plt.show()
#plt.savefig('figure2.png', dpi=600)
#plt.savefig('figure2.svg', )
plt.savefig('figure3.pdf', )
In [ ]:
plt.savefig('figure2.png')
In [17]:
plt.savefig('figure3.pdf', )
<Figure size 432x288 with 0 Axes>
In [20]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '.')

plt.show()
In [21]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--')

plt.show()
In [22]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '.-')

plt.show()
In [25]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='mediumblue')

plt.show()
In [26]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='0')

plt.show()
In [27]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='0.6')

plt.show()
In [28]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='#53694e')

plt.show()
In [30]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='#53694e')
ax.plot( [2,4] , [4,1], '-', c='red')

plt.show()
In [31]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='#53694e')
ax.plot( [2,4] , [4,1], '-', c='red', linewidth=3)

plt.show()
In [35]:
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '<', c='red')
ax.plot( [1,2,4] , [2,4,3], '>', c='blue')

plt.show()
In [3]:
import numpy as np

def f(x):
    return x**2


X = np.linspace(-2, 2, 100)
Y = f(X)

fig, ax = plt.subplots()
ax.plot( X , Y, '.', c='red')
In [37]:
X
Out[37]:
array([-2.        , -1.95959596, -1.91919192, -1.87878788, -1.83838384,
       -1.7979798 , -1.75757576, -1.71717172, -1.67676768, -1.63636364,
       -1.5959596 , -1.55555556, -1.51515152, -1.47474747, -1.43434343,
       -1.39393939, -1.35353535, -1.31313131, -1.27272727, -1.23232323,
       -1.19191919, -1.15151515, -1.11111111, -1.07070707, -1.03030303,
       -0.98989899, -0.94949495, -0.90909091, -0.86868687, -0.82828283,
       -0.78787879, -0.74747475, -0.70707071, -0.66666667, -0.62626263,
       -0.58585859, -0.54545455, -0.50505051, -0.46464646, -0.42424242,
       -0.38383838, -0.34343434, -0.3030303 , -0.26262626, -0.22222222,
       -0.18181818, -0.14141414, -0.1010101 , -0.06060606, -0.02020202,
        0.02020202,  0.06060606,  0.1010101 ,  0.14141414,  0.18181818,
        0.22222222,  0.26262626,  0.3030303 ,  0.34343434,  0.38383838,
        0.42424242,  0.46464646,  0.50505051,  0.54545455,  0.58585859,
        0.62626263,  0.66666667,  0.70707071,  0.74747475,  0.78787879,
        0.82828283,  0.86868687,  0.90909091,  0.94949495,  0.98989899,
        1.03030303,  1.07070707,  1.11111111,  1.15151515,  1.19191919,
        1.23232323,  1.27272727,  1.31313131,  1.35353535,  1.39393939,
        1.43434343,  1.47474747,  1.51515152,  1.55555556,  1.5959596 ,
        1.63636364,  1.67676768,  1.71717172,  1.75757576,  1.7979798 ,
        1.83838384,  1.87878788,  1.91919192,  1.95959596,  2.        ])
In [39]:
import numpy as np

def f(x):
    return x**2


X = np.linspace(-2, 2, 100)
Y = f(X)

fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
Out[39]:
[<matplotlib.lines.Line2D at 0x7fdf01bd86d0>]
In [42]:
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
Out[42]:
(-3.0, 1.0)
In [43]:
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_ylim((1,3))
Out[43]:
(1.0, 3.0)
In [50]:
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
Out[50]:
Text(0.5, 1.0, 'Amazing results')
In [52]:
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])
plt.show()
In [53]:
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])

ticks = ax.get_xticks().tolist()
ticks[2] = "test"
ax.set_xticklabels(ticks)

plt.show()
In [82]:
fig, ax = plt.subplots()
leg_1, = ax.plot( [1,2,4] , [3,5,4], '<', c='red')

#leg2, = ax.plot( [1,2,4] , [2,4,3], '>', c='blue')
# This is the same as:
leg_2 = ax.plot( [1,2,4] , [2,4,3], '>', c='blue')[0]

#ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
#ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
#ax.set_xticks([-2.5, -1, 0.5])

#ticks = ax.get_xticks().tolist()
#ticks[2] = "test"
#ax.set_xticklabels(ticks)

plt.legend([leg1, leg2], ['rats', 'mouse'], loc=4)

plt.show()
In [7]:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

sns.set_theme()
sns.set_style('white')# ('dark') # ("whitegrid")

def f(x):
    return x**2

X = np.linspace(-2, 2, 100)
Y = f(X)

fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])

ticks = ax.get_xticks().tolist()
ticks[2] = "test"
ax.set_xticklabels(ticks)
#ax.grid(True)

plt.show()
In [83]:
 
In [67]:
def f():
    return [1]

a, = f()
print (a)
1
In [68]:
def f():
    return [1,2]

a,b = f()
print (a,b)
1
In [69]:
def f():
    return [1]

a, = f()
print (a)
1
In [60]:
def f():
    return 1,2

a, = f()
print (a)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-60-21f0c826d110> in <module>
      2     return (1,2)
      3 
----> 4 a, = f()
      5 print (a)

ValueError: too many values to unpack (expected 1)
In [10]:
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])

ticks = ax.get_xticks().tolist()
ticks[2] = "test"
ax.set_xticklabels(ticks)
#ax.grid(True)

ax.text(-1, 3, 'hello')

plt.show()
In [11]:
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])

ticks = ax.get_xticks().tolist()
ticks[2] = "test"
ax.set_xticklabels(ticks)
#ax.grid(True)

ax.text(-1, 3, 'hello')

ax2 = ax.twinx()
ax2.plot([-2,-1, 0], [0.5, 1.5, 2.0])


plt.show()
In [17]:
fig, ax = plt.subplots(3,2)

ax[1][1].plot([1,5], [2,2], '-')

ax[2][0].plot(X, Y, '-')
Out[17]:
[<matplotlib.lines.Line2D at 0x7fef6ade4160>]
In [18]:
fig, ax = plt.subplots(3)
In [19]:
fig, ax = plt.subplots(1,3)
In [20]:
import plotly.express as px

fig=px.line(
    x=range(1,11), 
    y=[2,4,6,7,8,9,10,15,18,19], 
    labels={'x':'Day','y':'Number of new cases'})
fig.update_layout({'plot_bgcolor': '#d7dade','paper_bgcolor': '#d7dade'})
fig.show()
In [21]:
fig.write_html("file.html")
In [ ]: